home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gold Medal Software 5
/
Gold Medal Software - Volume 5 (Gold Medal) (1995).iso
/
windows
/
win31
/
cenviw.arj
/
SERVEOS2.CMM
< prev
next >
Wrap
Text File
|
1994-03-08
|
13KB
|
309 lines
//************************************************************************
//*** ServeOS2.cmm - Function to work with WIN_BOSS.LIB so that OS/2 ***
//*** ver.1 can control a Windows session. This program must ***
//*** be executed by CEnvi for Windows. A lot of ***
//*** execution time can be saved by /BINDing first. ***
//************************************************************************
if !defined(_WINDOWS_) {
printf("\a\nTHIS PROGRAM MUST BE EXECUTED ONLY BY CENVI FOR WINDOWS\n");
Instructions();
}
#include <OptParms.lib>
#include <Message.lib>
#include <WinTools.lib>
#include <WinUtil.lib>
#include <KeyPush.lib>
#include <MenuCtrl.lib>
#include <DlgCtrl.lib>
#include <ClipBrd.lib>
#define DEFAULT_MESSAGE_WAIT 500 // time to wait between messages
#define DEFAULT_PIPE_FILE_NAME "ServeOS2"
Instructions()
{
printf("\n")
printf("ServeOS2.cmm - Run Windows session under control of CEnvi WIN_BOSS script.\n")
printf("\n")
printf("SYNTAX: <path>\CEnvi ServeOS2 [options] [WinProgram args...]\n")
printf("\n")
printf("WHERE: path - Path to the Windows version of CEnvi\n")
printf(" WinProgram args...- Executable Windows program and parameters to that\n")
printf(" program. If supplied then ServeOS2.cmm will run until this\n")
printf(" program is no longer running.\n")
printf(" options:\n");
printf(" /DELAY time: time (milliseconds) to delay between checks; default %d\n",DEFAULT_MESSAGE_WAIT)
printf(" /NAME: Unique 8.3 name to identify ServeOS2 session: default %s\n",DEFAULT_PIPE_FILE_NAME)
printf("\n")
printf("EXAMPLES: C:\\CENVIW\\CEnvi ServeOS2\n")
printf(" C:\\CENVIW\\CEnvi ServeOS2 /DELAY 1000 /NAME Slave.doo\n")
printf(" C:\\CENVIW\\CEnvi ServeOS2 /NAME NOTE Notepad.exe c:\\Autoexec.bat\n")
printf("\n")
if ( defined(_WINDOWS_) )
getch();
exit(EXIT_FAILURE);
}
MessageWait = DEFAULT_MESSAGE_WAIT; // time to wait between messages
PFileName = DEFAULT_PIPE_FILE_NAME;
ReceivedQuitCommand = False;
main(argc,argv)
{
if ( argc == 2 && !strcmp(argv[1],"/?") )
Instructions();
// get some of the optional parameters
if OptionalParameter(argc,argv,"DELAY",sParm)
MessageWait = atoi(sParm);
OptionalParameter(argc,argv,"NAME",PFileName);
if ( 1 < argc ) {
// following parameters are for spawn, so build command and spawn
// application
for ( i = 1, ExecCmd = ""; i < argc; i++ ) {
strcat(ExecCmd,argv[i]);
strcat(ExecCmd," ");
}
ExecCmd[strlen(ExecCmd)-1] = 0; // no extra blank at end
if ( !(MasterWindowHwnd = spawn(P_NOWAIT,ExecCmd)) ) {
printf("\a\nUNABLE TO EXECUTE \"%s\"\n",ExecCmd);
Instructions();
}
}
RetitleThisWindow();
HideThisWindow();
RunForever(MasterWindowHwnd);
return EXIT_SUCCESS;
}
RetitleThisWindow() // give this window the ServeOS2 name
{
sprintf(NewTitle,"ServeOS2: %s",PFileName);
SetWindowTitle(ScreenHandle(),NewTitle);
}
HideThisWindow()
{
// set off the screen so it won't be seen
SetPosition(ScreenHandle(),-300,-300);
}
#define NO_WAIT_FOR_RETURN 0
#define WAIT_FOR_VOID_RETURN 1
#define WAIT_FOR_RETURN 2
RunForever(MasterHwnd)
{
sprintf(FullPipeSpec,"\\PIPE\\%s",PFileName);
while ( !ReceivedQuitCommand && (!defined(MasterHwnd) || IsWindow(MasterHwnd)) ) {
// try to read command from pipe file
if ( fp = fopen(FullPipeSpec,"r+b") ) {
// read integer for how many bytes in message
if ( fread(ReadCount,UWORD32,fp) ) {
undefine(lCommand);
if ( ReadCount == fread(lCommand,ReadCount,fp) ) {
rewind(fp);
lReturnCode = BLObGet(lCommand,0,SWORD32);
undefine(lResult);
if ( NO_WAIT_FOR_RETURN == lReturnCode ) {
// return fwrite immediately
BLObSize(lResult,1);
fwrite(BLObSize(lResult),UWORD32,fp);
fwrite(lResult,BLObSize(lResult),fp);
fclose(fp);
fp = NULL;
}
ExecuteFunction(lCommand,lReturnCode,lResult);
if ( NO_WAIT_FOR_RETURN != lReturnCode ) {
fwrite(BLObSize(lResult),UWORD32,fp);
fwrite(lResult,BLObSize(lResult),fp);
}
}
}
if ( fp ) fclose(fp);
}
suspend(MessageWait);
}
}
ExecuteFunction(pCmdBLOb,pReturnCode,pResultBLOb)
{
lExpectReturn = (WAIT_FOR_RETURN == pReturnCode);
// get function name
lNameSize = BLObGet(pCmdBLOb,lBLObOffset = 4,UWORD32);
lFuncName = BLObGet(pCmdBLOb,lBLObOffset += 4,lNameSize);
lBLObOffset += lNameSize;
// get count for how many variable to send to function
lVarCount = BLObGet(pCmdBLOb,lBLObOffset,UWORD32);
lBLObOffset += 4;
if ( lVarCount < 1 ) {
if ( lExpectReturn ) lRet = function(lFuncName);
else function(lFuncName);
} else {
lVar1 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 2 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1);
else function(lFuncName,lVar1);
} else {
lVar2 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 3 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2);
else function(lFuncName,lVar1,lVar2);
} else {
lVar3 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 4 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3);
else function(lFuncName,lVar1,lVar2,lVar3);
} else {
lVar4 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 5 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4);
} else {
lVar5 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 6 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5);
} else {
lVar6 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 7 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6);
} else {
lVar7 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 8 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7);
} else {
lVar8 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 9 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8);
} else {
lVar9 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 10 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9);
} else {
lVar10 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 11 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10);
} else {
lVar11 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 12 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11);
} else {
lVar12 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 13 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12);
} else {
lVar13 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 14 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12,lVar13);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12,lVar13);
} else {
lVar14 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 15 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12,lVar13,lVar14);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12,lVar13,lVar14);
} else {
lVar15 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 16 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12,lVar13,lVar14,lVar15);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12,lVar13,lVar14,lVar15);
} else {
lVar16 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 17 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12,lVar13,lVar14,lVar15,lVar16);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12,lVar13,lVar14,lVar15,lVar16);
} else {
lVar17 = GetNextExecVar(pCmdBLOb,lBLObOffset);
if ( lVarCount < 18 ) {
if ( lExpectReturn ) lRet = function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12,lVar13,lVar14,lVar15,lVar16,lVar17);
else function(lFuncName,lVar1,lVar2,lVar3,lVar4,lVar5,lVar6,lVar7,lVar8,lVar9,lVar10,lVar11,lVar12,lVar13,lVar14,lVar15,lVar16,lVar17);
} else {
printf("\aEEEEK! TOO MANY VARIABLES\n");
getch();
abort();
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
}
undefine(pResultBLOb);
if ( lExpectReturn ) {
if ( 1 == DataDimension(lRet) ) {
if ( CMM_BYTE != DataType(lRet) ) {
printf("\nServeOS2 arrays may only be byte-type and 1 dimensional.\a\n");
getch();
abort();
}
lVarLen = 1+GetArraySpan(lRet);
BLObPut(pResultBLOb,lVarLen,SWORD32);
BLObPut(pResultBLOb,lRet,lVarLen);
} else {
// convert return variable to blob to send back
lDataType = DataType(lRet);
BLObPut(pResultBLOb,-lDataType,SWORD32);
switch ( lDataType ) {
case CMM_BYTE: BLObPut(pResultBLOb,lRet,UWORD8); break;
case CMM_INT: BLObPut(pResultBLOb,lRet,SWORD32); break;
case CMM_FLOAT: BLObPut(pResultBLOb,lRet,FLOAT64); break;
default:
printf("\nServeOS2 data type must be byte, integer, or float.\n\a");
getch();
abort();
}
}
} else {
// simply return a byte to indicate that function is finished
BLObSize(pResultBLOb,1);
}
}
GetNextExecVar(pBLOb,pOffset)
{
switch ( lTypeOrLen = BLObGet(pBLOb,(pOffset += 4)-4,SWORD32) ) {
case (-CMM_BYTE): lRet = BLObGet(pBLOb,pOffset,UWORD8); pOffset++; break;
case (-CMM_INT): lRet = BLObGet(pBLOb,pOffset,SWORD32); pOffset += 4; break;
case (-CMM_FLOAT): lRet = BLObGet(pBLOb,pOffset,FLOAT64); pOffset += 8; break;
default: lRet = BLObGet(pBLOb,pOffset,lTypeOrLen); pOffset += lTypeOrLen; break;
}
return lRet;
}
// The following are all commands that might be called
ServeOS2Exit()
{
ReceivedQuitCommand = True;
}